package Eyjafjalla.effect;

import Eyjafjalla.helper.StringHelper;
import Eyjafjalla.patch.MelodyPatch;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.localization.UIStrings;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;

public class FloatWordEffect extends AbstractGameEffect {
    //悬浮词语特效，用以在旋律期间，在屏幕中显示音符（Do🎶 Re🎶 Mi🎶 Fa🎶 Sol🎶 La🎶 Ti🎶）
    public static final UIStrings uiStrings;
    private static final float YSPEED = 64F;
    private float x;
    private float y;
    private float xSpeed;
    private float ySpeed;
    private float xAcceleration;
    private float yAcceleration;
    float scale;
    float scaleSpeed;
    String description;

    public FloatWordEffect(){
        this.duration = MathUtils.random(2.2F,2.7F);
        startingDuration = duration;
        description = uiStrings.TEXT[MathUtils.random(0,6)];
        float ySet = -1F;
        if(MathUtils.randomBoolean())
            ySet = 1F;
        this.x = MelodyPatch.ALL_MELODY_START_X + MathUtils.random(0.15F,1.35F)*MelodyPatch.NOTE_DISTANCE_X;
        this.y = MelodyPatch.ALL_MELODY_START_Y + ySet*MathUtils.random(0.35F,0.45F)*MelodyPatch.BAR_HEIGHT;
        this.scale = MathUtils.random(1.0F,1.12F);
        this.scaleSpeed = 2.5F*scale/duration;
        this.scale = 0;
        this.xSpeed = MelodyPatch.NOTE_DISTANCE_X*MathUtils.random(1.4F,2.0F);
        this.ySpeed = ySet*YSPEED* Settings.yScale*MathUtils.random(0.5F,0.7F);
        this.xAcceleration = this.xSpeed * 0.5F;
        this.yAcceleration = -ySet*YSPEED*Settings.yScale/this.duration;
        this.color = new Color(MathUtils.random(0.2F,0.8F),MathUtils.random(0.2F,0.8F),MathUtils.random(0.2F,0.8F),1F);
    }

    @Override
    public void update() {
        float delta = Gdx.graphics.getDeltaTime();
        this.xSpeed += delta*xAcceleration;
        this.ySpeed += delta*yAcceleration;
        x += delta*xSpeed;
        y += delta*ySpeed;

        if(duration>0.6*startingDuration)
            this.scale += delta*scaleSpeed;
        else if(duration<0.4*startingDuration)
            this.scale -= delta*scaleSpeed;

        this.duration -= delta;
        if(duration<0F){
            this.isDone = true;
        }
    }

    @Override
    public void render(SpriteBatch sb) {
        if(scale>0)
            FontHelper.renderFontCentered(sb,FontHelper.cardTitleFont,description,this.x,this.y,this.color,scale);
    }

    @Override
    public void dispose() {

    }

    static {
        uiStrings = CardCrawlGame.languagePack.getUIString(StringHelper.MELODY_WORD);
    }
}
